package com.member.web.controller.shop;

import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizNotify;
import com.member.shop.domain.SysBizNotifyUser;
import com.member.shop.service.ISysBizNotifyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【公告通知】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-11-05
 **/
@RestController
@RequestMapping("/shop/notify")
public class SysBizNotifyController extends BaseController {
    @Resource
    private ISysBizNotifyService sysBizNotifyService;

    /**
     * 查询公告通知列表
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizNotify sysBizNotify) {
        startPage();
        setTenantId(sysBizNotify);
        List<SysBizNotify> list = sysBizNotifyService.selectSysBizNotifyList(sysBizNotify);
        return getDataTable(list);
    }

    private void setTenantId(SysBizNotify sysBizNotify) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizNotify.setTenantId(tenantId);
        }
    }

    /**
     * 导出公告通知列表
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:export')")
    @Log(title = "公告通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizNotify sysBizNotify) {
        setTenantId(sysBizNotify);
        List<SysBizNotify> list = sysBizNotifyService.selectSysBizNotifyList(sysBizNotify);
        ExcelUtil<SysBizNotify> util = new ExcelUtil<SysBizNotify>(SysBizNotify.class);
        util.exportExcel(response, list, "公告通知数据");
    }

    /**
     * 获取公告通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizNotifyService.selectSysBizNotifyById(id));
    }

    /**
     * 新增公告通知
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:add')")
    @Log(title = "公告通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizNotify sysBizNotify) {
        return toAjax(sysBizNotifyService.insertSysBizNotify(sysBizNotify));
    }

    /**
     * 修改公告通知
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:edit')")
    @Log(title = "公告通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizNotify sysBizNotify) {
        return toAjax(sysBizNotifyService.updateSysBizNotify(sysBizNotify));
    }


    /**
     * 删除公告通知
     */
    @PreAuthorize("@ss.hasPermi('shop:notify:remove')")
    @Log(title = "公告通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {

        return toAjax(sysBizNotifyService.deleteSysBizNotifyByIds(ids));
    }
}
